import type { ProviderChannelConfig, Provider, Channel } from './ProviderChannelConfig';

// 示例数据
export const mockProviders: Provider[] = [
  {
    id: '1',
    name: '火金科技',
    code: 'HUOJIN',
    status: '1'
  }
]

export const mockChannels: Channel[] = [
  {
    id: '1',
    name: '微信支付',
    code: 'WECHAT',
    status: '1'
  },
  {
    id: '2',
    name: '支付宝',
    code: 'ALIPAY',
    status: '1'
  },
  {
    id: '3',
    name: '乐刷支付',
    code: 'LESHUA',
    status: '1'
  },
  {
    id: '4',
    name: '斗拱支付',
    code: 'DOUGONG',
    status: '1'
  }
]

// Mock数据 - 基于 data.ts 的配置
const mockProviderChannelConfigs: ProviderChannelConfig[] = [
  {
    id: 1,
    providerId: 1,
    channelId: 1,
    isSandbox: 1,
    baseConfig: JSON.stringify({
      mchId: '1677504495',
      mchApiKeyV2: 'IU8xBYRJ****AEzInnZR',
      mchApiKeyV3: 'ZyRkYbMC****jTziTioy',
      mchSerialNo: '689D2D6838A21BEBBFBCA38F67C3259CC0D6D9FC',
      certPath: '/home/bera/anypay/anypay-manager/www/isv-cert/apiclient_cert.p12',
      certPassword: '1677504495',
      privateKeyPath: '/home/bera/anypay/anypay-manager/www/isv-cert/apiclient_key.pem',
      publicKeyPath: '/home/bera/anypay/anypay-manager/www/isv-cert/apiclient_cert.pem',
      platformCertPath: '/path/to/cert/platform_cert.pem',
      notifyUrl: 'https://pay.shouyin.com',
      apiVersion: 'v3',
      domain: 'https://api.mch.weixin.qq.com',
      connectTimeout: 5000,
      readTimeout: 10000,
      writeTimeout: 10000
    }),
    feeConfig: JSON.stringify({
      rate: 0.006,
      minFee: 0.01,
      maxFee: 1000
    }),
    extraConfig: JSON.stringify({
      remark: '微信支付服务商配置'
    }),
    status: 1,
    createdAt: '2024-03-20 10:00:00',
    updatedAt: '2024-03-20 10:00:00'
  },
  {
    id: 2,
    providerId: 1,
    channelId: 2,
    isSandbox: 1,
    baseConfig: JSON.stringify({
      appId: '2021000000000000',
      privateKey: 'MIIEvQIBADANBgkqhkiG9w0BAQEF...',
      publicKey: 'MIIBIjANBgkqhkiG9w0BAQEF...',
      notifyUrl: 'https://api.example.com/notify/alipay'
    }),
    feeConfig: JSON.stringify({
      rate: 0.006,
      minFee: 0.01,
      maxFee: 1000
    }),
    extraConfig: JSON.stringify({
      subAppId: '2021000000000001',
      subMchId: '2088000000000001',
      remark: '支付宝配置'
    }),
    status: 1,
    createdAt: '2024-03-20 10:00:00',
    updatedAt: '2024-03-20 10:00:00'
  },
  {
    id: 3,
    providerId: 1,
    channelId: 3,
    isSandbox: 1,
    baseConfig: JSON.stringify({
      appId: 'ls123456789',
      mchId: '1234567890',
      apiKey: 'abcdef123456',
      notifyUrl: 'https://api.example.com/notify/leshua'
    }),
    feeConfig: JSON.stringify({
      rate: 0.006,
      minFee: 0.01,
      maxFee: 1000
    }),
    extraConfig: JSON.stringify({
      remark: '乐刷支付配置'
    }),
    status: 1,
    createdAt: '2024-03-20 10:00:00',
    updatedAt: '2024-03-20 10:00:00'
  },
  {
    id: 4,
    providerId: 1,
    channelId: 4,
    isSandbox: 1,
    baseConfig: JSON.stringify({
      appId: 'dg123456789',
      mchId: '2023001234567890',
      apiKey: 'dougong_api_key_123456',
      secretKey: 'dougong_secret_key_654321',
      notifyUrl: 'https://api.example.com/notify/dougong',
      apiUrl: 'https://api.dougong.com',
      certFile: '/uploads/certs/dougong_cert_20240320.p12'
    }),
    feeConfig: JSON.stringify({
      rate: 0.006,
      minFee: 0.01,
      maxFee: 1000
    }),
    extraConfig: JSON.stringify({
      remark: '斗拱支付配置',
      version: '1.0'
    }),
    status: 1,
    createdAt: '2024-03-20 10:00:00',
    updatedAt: '2024-03-20 10:00:00'
  }
];

// 获取Mock数据
export const getMockProviderChannelConfigData = (pageNumber: number, pageSize: number) => {
  const start = (pageNumber - 1) * pageSize;
  const end = start + pageSize;
  const data = mockProviderChannelConfigs.slice(start, end);

  return Promise.resolve({
    success: true,
    data,
    total: mockProviderChannelConfigs.length,
    current: pageNumber,
    size: pageSize
  });
};

// Mock添加
export const mockAddProviderChannelConfig = (data: Partial<ProviderChannelConfig>) => {
  const newConfig: ProviderChannelConfig = {
    id: Date.now(),
    providerId: data.providerId || 1,
    channelId: data.channelId || 1,
    isSandbox: data.isSandbox || 1,
    baseConfig: data.baseConfig || '{}',
    feeConfig: data.feeConfig || '{}',
    extraConfig: data.extraConfig || '{}',
    status: data.status || 1,
    createdAt: new Date().toLocaleString(),
    updatedAt: new Date().toLocaleString()
  };

  mockProviderChannelConfigs.unshift(newConfig);

  return Promise.resolve({
    success: true,
    message: '添加成功'
  });
};

// Mock编辑
export const mockEditProviderChannelConfig = (id: number, data: Partial<ProviderChannelConfig>) => {
  const index = mockProviderChannelConfigs.findIndex(config => config.id === id);
  if (index !== -1) {
    mockProviderChannelConfigs[index] = {
      ...mockProviderChannelConfigs[index],
      ...data,
      updatedAt: new Date().toLocaleString()
    };
    return Promise.resolve({
      success: true,
      message: '编辑成功'
    });
  }
  return Promise.resolve({
    success: false,
    message: '配置不存在'
  });
};

// Mock删除
export const mockDeleteProviderChannelConfig = (id: number) => {
  const index = mockProviderChannelConfigs.findIndex(config => config.id === id);
  if (index !== -1) {
    mockProviderChannelConfigs.splice(index, 1);
    return Promise.resolve({
      success: true,
      message: '删除成功'
    });
  }
  return Promise.resolve({
    success: false,
    message: '配置不存在'
  });
};

// Mock获取详情
export const mockFetchProviderChannelConfigDetail = (id: number) => {
  const config = mockProviderChannelConfigs.find(config => config.id === id);
  if (config) {
    return Promise.resolve({
      success: true,
      data: config
    });
  }
  return Promise.resolve({
    success: false,
    message: '配置不存在'
  });
};